<%@page pageEncoding="UTF-8"%>
<%@page trimDirectiveWhitespaces="true" %>
<%@taglib prefix="commonTag" 	tagdir="/WEB-INF/tags/common/html"%>
<%@taglib prefix="prototypeUI"	tagdir="/WEB-INF/tags/common/Prototype"%>
<!DOCTYPE html>
<html>
<commonTag:head lessFile="/admin/asset/less/main.less">
	<%@ include file="../public/head.jsp" %>
</commonTag:head>
<body>
	<prototypeUI:nav />
	<div class="widget-box">
		<form class="form-horizontal" method="post" >
			<div class="control-group">
				<label class="control-label">用户名：</label>
				<div class="controls">
					Admin
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">原密码:</label>
				<div class="controls">
					<input name="oldPassword" type="password" class="ui-wizard-content" placeholder="请输入旧密码" errmsg="旧密码为必填项" requiredfield />
					<span class="requiredfield">*</span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">新密码:</label>
				<div class="controls">
					<input name="password" type="password" class="ui-wizard-content" placeholder="请输入新密码" errmsg="新密码为必填项" requiredfield />
					<span class="requiredfield">*</span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">确认密码:</label>
				<div class="controls">
					<input name="newPassword2" type="password" class="ui-wizard-content"  placeholder="请重复输入新密码" errmsg="要重复输入您刚才输入的密码" requiredfield />
					<span class="requiredfield">*</span>
				</div>
			</div>
			<div class="form-actions">
		        <button class="btn btn-success submitBtn">保存</button>
		    </div>
		</form>
	</div>
	<script>
		seajs.use(['bigfoot/common', 'bigfoot/dhtml/form/form', 'libs/md5_2.js'], 
           function($, form){
	           var formEl = document.querySelector('form');
	       	
	           // 判断旧密码是否正确    
	           var _form = Object.create(form);
	           _form.action = '../../service/user/updatePassword';
	           _form.formEl = formEl;
	           _form.beforeSubmit = function(){
					// debugger;
	               var oldPassword = formEl.$('input[name=oldPassword]');
	               oldPassword.value = md5(oldPassword.value);
	               // MD5
	               var password  = formEl.$('input[name=password]'),
	                   password2 = formEl.$('input[name=newPassword2]');
	               
	               if(password.value != password2.value){
	            	   $.alert('两次输入的密码不一致哦~');
	            	   return false;
	               }
	
	               password.value = password2.value = md5(password.value);     
	           }
	           _form.onSubmitSuccuess = function(result){
	        	   formEl.reset();
	               if(result.isOk){
	                  $.msg('修改成功！');
	               }else{
	            	   $.alert(result.msg);
	               }
	           }
	           _form.init();
       });
	</script>
</body>
</html>